package com.deng.api.service.impl;

import cn.hutool.core.util.StrUtil;
import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.deng.api.entity.CloudCity;
import com.deng.api.mapper.CloudCityMapper;
import com.deng.api.service.ICloudCityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deng.api.vo.PageVO;
import com.deng.commons.common.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author deng
 * @since 2022-08-10
 */
@Service
public class CloudCityServiceImpl extends ServiceImpl<CloudCityMapper, CloudCity> implements ICloudCityService {
    @Resource
    private CloudCityMapper cloudCityMapper;

    @Override
    public BaseResult getCityAll(Integer page, Integer size, String name) {
        Page<CloudCity> p = new Page<>();
        LambdaQueryWrapper<CloudCity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (!StrUtil.isEmptyIfStr(name)){
            lambdaQueryWrapper.like(CloudCity::getName,name);
        }
        Page<CloudCity> cloudCityPage = cloudCityMapper.selectPage(p, lambdaQueryWrapper);
        return BaseResult.success(PageVO.toPageVO(cloudCityPage));
    }
}
